import { CloudDBZoneWrapper } from '../clouddb/CloudDBZoneWrapper';
import * as Utils from '../utils/Utils.js';

export const myHandler = async function (event, context, callback, logger) {
  const credential = Utils.getCredential(context, logger);
  try {
    const cloudDBZoneWrapper = new CloudDBZoneWrapper(credential, logger);
    const result = await cloudDBZoneWrapper.queryOrderStatic();

    callback({
      ret: { code: 0, desc: "SUCCESS" },
      result: [
        {
          "order_count": result.order_count,
          "order_max": result.order_max,
          "order_min": result.order_min,
          "order_sum": result.order_sum,
          "order_avg": result.order_avg
        }],
    });

  } catch (err) {
    logger.error("func error:" + err.message + " stack:" + err.stack);
    callback({
      ret: { code: -1, desc: "ERROR" },
    });
  }
};
